﻿using FS.Common.DotNetJson;
using FS.Common.DotNetCode;
using FS.Business;
using System;
using System.Data;
using System.Web;
using System.Web.SessionState;

namespace FS.Web.BLL.Visa_Base
{
    /// <summary>
    /// Summary description for CityUser
    /// </summary>
    public class CityUser : IHttpHandler, IRequiresSessionState
    {
        private visa_dao _visa = new visa_dao();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1.0);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            string Action = context.Request["action"];            
            string cityid = context.Request["cityid"];
            string id = context.Request["id"];
                      
            string text = Action;
            if (text != null)
            {
                if (text == "GetAllUser") //获取系统用户
                {
                    DataTable dt = _visa.Ajax_GetAllUser();
                    string sb = JsonHelper.DataTableToJsonData(dt);

                    context.Response.Write(sb.ToString());
                    context.Response.End();
                }
                else if (text == "GetCityUser") //获取可操作当前国家的用户
                {
                    DataTable dt = _visa.Ajax_GetCityUser(cityid);
                    string sb = JsonHelper.DataTableToJsonData(dt);

                    context.Response.Write(sb.ToString());
                    context.Response.End();
                }
                else if (text == "delete") //删除国家用户信息
                {
                    string[] delid =id.Split(',');

                    int Return = _visa.Ajax_DeleteCountryUser(delid);
                    if (Return > 0) CacheHelper.RemoveAllCache("CityUser");
                    context.Response.Write(Return.ToString());
                }
                else if (text == "add") //添加国家用户信息
                {
                    int Return = _visa.Ajax_AddCountryUser(cityid,id);
                    if (Return > 0) CacheHelper.RemoveAllCache("CityUser");
                    context.Response.Write(Return.ToString());
                } 
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}